package com.leyou.item.client;

import com.leyou.common.dto.PageDTO;
import com.leyou.item.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient("item-service")
public interface ItemFeignClient {
    /**
     * 分页查询spu表
     *
     * @param page
     * @param rows
     * @param brandId
     * @param categoryId
     * @param id
     * @param saleable
     * @return
     */
    @GetMapping("/goods/spu/page")
    PageDTO<SpuDTO>querySpuPage(
            @RequestParam(value = "page", defaultValue = "1") Long page,
            @RequestParam(value = "rows", defaultValue = "5") Long rows,
            @RequestParam(value = "brandId", required = false) Long brandId,
            @RequestParam(value = "categoryId", required = false) Long categoryId,
            @RequestParam(value = "id", required = false) Long id,
            @RequestParam(value = "saleable", required = false) Boolean saleable
    );



    /**
     * 根据商品spuID查询sku的集合
     *
     * @param spuID
     * @return
     */
    @GetMapping("/goods/sku/of/spu")
    List<SkuDTO> querySkuListBySpuID(@RequestParam("id") Long spuID);



    /**
     * 根据spuId,查询spu的所有规格参数,值value
     *
     * @param spuId
     * @param searching
     * @return
     */
    @GetMapping("/goods/spec/value")
    List<SpecParamDTO> querySpuValuesBySpuId(
            @RequestParam("id") Long spuId,
            @RequestParam(value = "searching", required = false) Boolean searching
    );


    /**
     * 根据品牌id集合查询品牌集合
     *
     * @param ids
     * @return
     */
    @GetMapping("/brand/list")
    List<BrandDTO> queryBrandsByIds(@RequestParam("ids") List<Long> ids);


    /**
     * 根据分类id的集合，查询商品分类的集合
     * 补充：在spring-mvc中为我们提供了接收数据的方法,直接使用集合接收
     *
     * @RequestParam("list") List<Integer> ids
     * http://127.0.0.1:8081/category/list?ids=12,13,46
     */
    @GetMapping("/category/list")
    List<CategoryDTO> queryCategoriesByIds(@RequestParam("ids") List<Long> ids);



    /**
     * 根据商品spuID查询商品
     *
     * @param spuID
     * @return
     */
    @GetMapping("/goods/spu/{id}")
    SpuDTO querySpuBySpuID(@PathVariable("id") Long spuID);


    /**
     * 根据商品spuID查询商品详情
     *
     * @param spuID
     * @return
     */
    @GetMapping("/goods/spu/detail")
    SpuDetailDTO querySpuDetailBySpuID(@RequestParam("id") Long spuID);


    /**
     * 根据id查询品牌
     *
     * @param id
     * @return
     */
    @GetMapping("/brand/{id}")
    BrandDTO queryBrandById(@PathVariable("id") Long id);


    /**
     * 根据分类id查询规格组,规格参数
     *
     * @param cid
     * @return
     */
    @GetMapping("/spec/list")
    List<SpecGroupDTO> querySpecGroupListById(@RequestParam("id") Long cid);


    /**
     * 根据id批量查询sku
     *
     * @param ids
     * @return
     */
    @GetMapping("/goods/sku/list")
    List<SkuDTO> querySkuListByIds(@RequestParam("ids") List<Long> ids);


    /**
     * 商品减库存
     * @param cartsMap
     * @return
     */
    @PutMapping("/goods/stock/minus")
    void subtractStock(@RequestBody Map<Long, Integer> cartsMap);
}
